package test2;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;

public class TestPTPConsumerSyn {
	public static void main(String[] args) throws JMSException {
		ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://10.222.29.178:61616");
		Destination queue = new ActiveMQQueue("jason");
		Connection con = factory.createConnection();
		con.start();
		
		Session session = con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
		MessageConsumer consumer = session.createConsumer(queue);
		
		//block thread
		TextMessage msg = (TextMessage) consumer.receive();
		String string = msg.getText();
		System.out.println(string);
		
		//consumer acknowledge receive
		msg.acknowledge();
		
		session.close();
		con.close();
	}
}
